package Homework.apiDay04;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class FisAndFosDemo {
    public static void main(String[] args) throws IOException {
        String line = "自控力与行动力以及智慧,情感";
        File file = new File("test.txt");
        FileOutputStream fos1 = new FileOutputStream("test_cope.txt");
        FileOutputStream fos = new FileOutputStream("test.txt");
        FileInputStream fis = new FileInputStream("test.txt");

        byte[] data = line.getBytes(StandardCharsets.UTF_8);
        System.out.println(Arrays.toString(data));
        fos.write(data);
        System.out.println("写出成功");
        fis.read(data);
        System.out.println(Arrays.toString(data));
        String show = new String(data,StandardCharsets.UTF_8);
        System.out.println(show);

        fos.close();
        fis.close();
        FileInputStream fis1 = new FileInputStream("test.txt");
        byte[] read = new byte[(int)file.length()];
        fis1.read(read);
        System.out.println(Arrays.toString(read));


        fos1.write(read);
        fos1.close();
    }
}
